home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 311_01 / vtest.c < prev   
C/C++ Source or Header  |  1990-04-21  |  6KB  |  186 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      vtest.c  v1.3  (c) 1990  Ken Harris                                 */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8. /*                                                                          */
  9. /*      This software is made available on an AS-IS basis. Unrestricted     */
  10. /*      use is granted provided that the copyright notice remains intact.   */
  11. /*      The author makes no warranties expressed or implied.                */
  12. /*                                                                          */
  13. /****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include "db.h"
  17.  
  18. main()
  19. {
  20.         DATA_SET ds;
  21.         char     data[50];
  22.         int      i, size;
  23.     long     psn;
  24.  
  25.     printf("vtest - Test variable file routines\n\n");
  26.     vcreate();
  27.         printf("...test file created...\n\n");
  28.  
  29.     ds = db_open("", "vtest.dat");
  30.         if (db_error)
  31.         {       printf("Open Failure - %s\n", db_error_msg(db_error));
  32.                 exit(0);
  33.         }
  34.  
  35.         printf("...adding 100 records...\n");
  36.         for (i=1; i<=100; i++)
  37.         {       sprintf(data,"%06d",i);
  38.                 psn = db_add(ds, data, 6);
  39.                 printf("%d (psn=%ld)\n",i,psn);
  40.  
  41.                 if (db_error)
  42.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  43.                         exit(0);
  44.                 }
  45.  
  46.         }
  47.         printf("...add complete...\n\n");
  48.  
  49.     printf("...reorg...\n");
  50.     db_reorg(ds);
  51.     if (db_error) printf("Reorg Failure - %s\n", db_error_msg(db_error));
  52.     printf("...reorg complete...\n");
  53.  
  54.     printf("...read forward...\n");
  55.     db_read_first(ds, data, &size);
  56.     while (!db_error)
  57.     {    psn = db_get_rec_no(ds);
  58.         printf("%6.6s (size=%d  psn=%ld)\n", data, size, psn);
  59.         data[0] = '_';
  60.         db_update(ds, data);
  61.         db_read_next(ds, data, &size);
  62.     }
  63.     printf("...read forward complete...\n\n");
  64.  
  65.     printf("...reorg...\n");
  66.     db_reorg(ds);
  67.     if (db_error) printf("Reorg Failure - %s\n", db_error_msg(db_error));
  68.     printf("...reorg complete...\n");
  69.  
  70.         printf("...read reverse...\n");
  71.     db_read_last(ds, data, &size);
  72.     while (!db_error)
  73.     {    psn = db_get_rec_no(ds);
  74.         db_read_direct(ds, psn, data, &size);
  75.         if (db_error)
  76.         {    printf("%s\n",db_error_msg(db_error));
  77.             break;
  78.         }
  79.         printf("%6.6s (size=%d  psn=%ld)\n", data, size, psn);
  80.         db_read_prev(ds, data, &size);
  81.     }
  82.     printf("...read reverse complete...\n\n");
  83.  
  84.     printf("...reorg...\n");
  85.     db_reorg(ds);
  86.     if (db_error) printf("Reorg Failure - %s\n", db_error_msg(db_error));
  87.     printf("...reorg complete...\n");
  88.  
  89.     printf("...delete forward...\n");
  90.     db_read_first(ds, data, &size);
  91.     while (!db_error)
  92.     {    printf("%6.6s\n", data);
  93.         db_delete(ds);
  94.         db_read_next(ds, data, &size);
  95.     }
  96.     printf("...delete forward complete...\n\n");
  97.  
  98.     printf("...reorg...\n");
  99.     db_reorg(ds);
  100.     if (db_error) printf("Reorg Failure - %s\n", db_error_msg(db_error));
  101.     printf("...reorg complete...\n");
  102.  
  103.     printf("...read forward...\n");
  104.     db_read_first(ds, data, &size);
  105.     while (!db_error)
  106.     {    printf("%6.6s (%d)\n", data, size);
  107.         db_read_next(ds, data, &size);
  108.     }
  109.     printf("...read forward complete...\n\n");
  110.  
  111.         printf("...read reverse...\n");
  112.     db_read_last(ds, data, &size);
  113.     while (!db_error)
  114.     {    printf("%6.6s (%d)\n", data, size);
  115.         db_read_prev(ds, data, &size);
  116.     }
  117.     printf("...read reverse complete...\n\n");
  118.  
  119.         printf("...adding 100 records (again) ...\n");
  120.         for (i=1; i<=100; i++)
  121.         {       printf("%d\n",i);
  122.                 sprintf(data,"%06d",i);
  123.                 db_add(ds, data, 6);
  124.                 if (db_error)
  125.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  126.                         exit(0);
  127.                 }
  128.         }
  129.         printf("...add complete...\n\n");
  130.  
  131.     printf("...read forward...\n");
  132.     db_read_first(ds, data, &size);
  133.     while (!db_error)
  134.     {    printf("%6.6s (%d)\n", data, size);
  135.         db_read_next(ds, data, &size);
  136.     }
  137.     printf("...read forward complete...\n\n");
  138.  
  139.         printf("...delete reverse...\n");
  140.     db_read_last(ds, data, &size);
  141.     while (!db_error)
  142.     {    printf("%6.6s (%d)\n", data, size);
  143.         db_delete(ds);
  144.         db_read_prev(ds, data, &size);
  145.     }
  146.     printf("...delete reverse complete...\n\n");
  147.  
  148.     printf("...read forward...\n");
  149.     db_read_first(ds, data, &size);
  150.     while (!db_error)
  151.     {    printf("%6.6s (%d)\n", data, size);
  152.         db_read_next(ds, data, &size);
  153.     }
  154.     printf("...read forward complete...\n\n");
  155.  
  156.     printf("...reorg...\n");
  157.     db_reorg(ds);
  158.     if (db_error) printf("Reorg Failure - %s\n", db_error_msg(db_error));
  159.     printf("...reorg complete...\n");
  160.  
  161.         db_close(ds);
  162.     unlink("vtest.dat");
  163. }
  164.  
  165. /*
  166.  *    vcreate - create our test variable file
  167.  */
  168.  
  169. vcreate()
  170. {
  171.         DATA_SET ds;
  172.  
  173.  
  174.     ds = db_create("", "vtest.dat", "var,rec=50");
  175.         if (db_error)
  176.         {       printf("Create Failure - %s\n", db_error_msg(db_error));
  177.                 exit(0);
  178.         }
  179.  
  180.         db_close(ds);
  181.         if (db_error)
  182.         {       printf("Close Failure - %s\n", db_error_msg(db_error));
  183.                 exit(0);
  184.         }
  185. }
  186.